<?php
	require_once('./config.php');
	require_once('./oauth.php');

	if(isset($_GET['action']))
		switch ($_GET['action'])
		{
			case 'auth':
				OAuth_1();
				break;
			case 'savecookie':
				session_start();
				if( isset($_SESSION['oauth_token']) && isset($_SESSION['oauth_token_secret']) )
				{
					setcookie('oauth_token', $_SESSION['oauth_token'], time()+3600*24*365*10, $path, $_SERVER['HTTP_HOST']);
					setcookie('oauth_token_secret', $_SESSION['oauth_token_secret'], time()+3600*24*365*10, $path, $_SERVER['HTTP_HOST']);
					header('Location: ./feed.php');
				}
				else
				{
					$error='LOST: oauth_token OR oauth_token_secret<br />cookie is NOT saved';
					FailPage($error);
				}
				break;
			case 'clearcookie';
				setcookie('oauth_token', NULL);
				setcookie('oauth_token_secret', NULL);
				$error='cookie is cleared';
				FailPage($error);
				break;
			default:
				header('Location: ./');
		}
		else
			header('Location: ./');
?>